import 'package:flutter/material.dart';
import 'package:ninetyfour/l10n/app_localizations.dart';

class LoginTopView extends StatefulWidget {
  final VoidCallback onBack;
  final VoidCallback onHelp;
  final int type;

  const LoginTopView({
    super.key,
    required this.onBack,
    required this.onHelp,
    required this.type,
  });

  @override
  State<LoginTopView> createState() => _LoginTopViewState();
}

class _LoginTopViewState extends State<LoginTopView> {
  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: 250,
      child: Stack(
        children: [
          // 背景图片
          Positioned.fill(
            child: Image.asset(
              widget.type == 1 ? 'assets/images/login_bg2.png' : 'assets/images/login_bg.png',
              fit: BoxFit.fill,
              width: double.infinity,
            ),
          ),

          // 返回按钮
          Positioned(
            left: 20,
            top: MediaQuery.of(context).padding.top + 5,
            child: IconButton(
              icon: Image.asset('assets/images/leftpush.png', width: 26, height: 26),
              onPressed: widget.onBack,
            ),
          ),

          // 客服按钮
          Positioned(
            right: 20,
            top: MediaQuery.of(context).padding.top + 5,
            child: TextButton(
              onPressed: () {
                widget.onHelp();
              },
              child: Text(
                AppLocalizations.of(context)!.haveAProblem,
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 15,
                ),
              ),
            ),
          ),

          // 应用图标
          Positioned(
            left: 35,
            top: MediaQuery.of(context).padding.top + 65,
            child: Image.asset(
              'assets/images/logo_mobil.png',
              width: 135,
              height: 40,
            ),
          ),

          // 用户信息区域
          Positioned(
            left: 35,
            top: MediaQuery.of(context).padding.top + 112,
            child: Text(
              widget.type == 1 ? AppLocalizations.of(context)!.welcome : AppLocalizations.of(context)!.welcome2,
              style: TextStyle(
                color: widget.type == 1 ? Colors.white : const Color(0xFF5D5FEE),
                fontSize: 26,
                fontWeight: FontWeight.w600,
              ),
            ),
          ),

          // 右侧图标+描述
          Positioned(
            right: 45,
            top: MediaQuery.of(context).padding.top + 40,
            child: Stack(
              alignment: Alignment.center,  // 设置 Stack 内部组件的对齐方式
              children: [
                // 图片
                Image.asset(
                  widget.type == 1
                      ? 'assets/images/login_icon.png'
                      : 'assets/images/signin_icon.png',
                  width: 150,
                  height: 120,
                ),
                // 文字
                if (widget.type == 0)
                  Positioned(
                    top: 68,  // 设置文字距离图片顶部的距离
                    child: Text(
                      AppLocalizations.of(context)!.registerBonus,
                      textAlign: TextAlign.center,
                      style: TextStyle(
                        color: Color(0xFFE53935),
                        fontWeight: FontWeight.w600,
                        fontSize: isChineseLocale() ? 14 : 13,
                        height: 1.2,
                      ),
                    ),
                  ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}